/**
 * 转义正则
 */
export function escapeRegExp(s: string) {
	return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}

/**
 * 转义HTML
 */
export function escapeHTML(s: string) {
	const reg = /[<>"]/g;

	type Callback = (substring: string, ...args: any[]) => string;

	function callback(m: string) {
		switch (m) {
			case '<':
				return '&lt;';
			case '>':
				return '&gt;';
			case '"':
				return '&quot;';
			default:
				return m;
		}
	}

	return s.replace(reg, callback as Callback);
}
